//
//  HFStatusRweetedView.swift
//  sinaMicroBlog
//
//  Created by mac on 15/11/19.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit
import SnapKit

class HFStatusRweetedView: UIView {
    
    //添加约束更新
    var bottomConstrains: Constraint?
    //添加数据模型
    var retweetedStatus: HFStatus? {
        didSet {
            retweetedLabel.text = retweetedStatus?.text
            self.bottomConstrains?.uninstall()
            //判断是否有配图并更新约束
            if let pictureurls = retweetedStatus?.imageURLs where pictureurls.count > 0 {
                pictureView.imageURLs = pictureurls
                //显示图片
                pictureView.hidden = false
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstrains = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                    
                })
            }else {
                pictureView.hidden = true
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstrains = make.bottom.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin).constraint
                })
            }

        }
    }
    //init调用UI
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //设置UI
    private func setupUI() {
        addSubview(retweetedLabel)
        addSubview(pictureView)
        
        //约束
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top).offset(StatusCellMargin)
            make.left.equalTo(snp_left).offset(StatusCellMargin)
            
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            self.bottomConstrains = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }

    }
    //懒加载
    private lazy var retweetedLabel: UILabel = UILabel(title: "我是转发微博", size: 14, color: UIColor.darkGrayColor(), margin: StatusCellMargin)
    private lazy var pictureView: HFStatusPictureView = HFStatusPictureView()

}
